# Makes Figure 9, showing the relative value in different pathways
# Note that the results are "hard coded" in this script,
# so you need to use the other code to actually replicate the results!

# See "do_counterfactuals_insample.py" for the insample calculation
# See "do_counterfactuals_future.py" for the out of sample calculation

# Jacob Moscona and Karthik Sastry
# This version: last edited on September 28, 2022

import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
import os

wd = '/home/karthik/Dropbox (MIT)/climate_crops/QJE_Submission/Replication/Data/'
os.chdir(wd)



## Useful functions
def autolabel(rects,axis,clr='white',neg=True):
    for rect in rects:
        height = rect.get_height()
        nm = '{:.3f}'.format(height)
        v0 = 3
            
        axis.annotate(nm,
                    xy=(rect.get_x() + rect.get_width() / 2, height),
                    xytext=(0, v0),  # 3 points vertical offset
                    textcoords="offset points",
                    ha='center', va='bottom',
                    color = clr)

values = np.array([[33.21,	32.5], ## 45, 60, 80
               [34.43,	33.91],
               [31.2	,   30.07]])
values = values[[1,0,2],:]
name = ['RCP 6.0', 'RCP 4.5', 'RCP 8.5']



fig,ax = plt.subplots(1,1,figsize = (6,3))
    

## Relative damages
maxval = np.max(values.flatten())
values = values / maxval # Normalized
pos = np.array([0,1,2])
width = 0.35
colors = ('C0','C1','C2','k')

rects1 = ax.bar(pos - width/2, values[:,0], width, label='Innovation', color = colors[0])
rects2 = ax.bar(pos + width/2, values[:,1], width, label='No Innovation', color = colors[1])
ax.set_xticks(pos)
ax.set_xticklabels(name)

ax.set_ylabel('Relative Aggregate Land Value\n(Best Case = 1.0)')


# Labels
autolabel(rects1,ax,clr='black')
autolabel(rects2,ax,clr='black')

ax.set_ylim([0.8,1.05])

# Legend
ax.legend()


plt.savefig('../Results/Figure_9.pdf',
            bbox_inches='tight')

